﻿using FastEmit;

namespace FastApi
{
    public class FastAction
    {
        public FastAction(string httpMethod, string routeName, string methodName, bool clearFilter,
            MethodInvoker invoker, bool isStatic, Type returnType, FastActionType actionType, FastActionTypeTask typeTask,
            bool enableBuffer, string path)
        {
            HttpMethod = httpMethod.ToUpper();
            RouteName = routeName;
            Path = path;
            MethodName = methodName;
            ClearFilter = clearFilter;
            Invoker = invoker;
            IsStatic = isStatic;
            ActionType = actionType;
            ActionTypeTask = typeTask;
            ReturnType = returnType;
            EnableBuffering = enableBuffer;
        }

        public string HttpMethod { get; }

        /// <summary>
        /// 路由名称
        /// </summary>
        public string RouteName { get; }

        /// <summary>
        /// 完整路径
        /// </summary>
        public string Path { get; }

        /// <summary>
        /// 方法名称
        /// </summary>
        public string MethodName { get; }

        /// <summary>
        /// 是否清除过滤器
        /// </summary>
        public bool ClearFilter { get; }

        /// <summary>
        /// 方法委托
        /// </summary>
        public MethodInvoker Invoker { get; }

        /// <summary>
        /// 方法参数类型列表
        /// </summary>
        public List<FastParam> ParamList { get; } = [];

        /// <summary>
        /// 是否静态方法
        /// </summary>
        public bool IsStatic { get; }

        /// <summary>
        /// 方法返回类型
        /// </summary>
        public Type ReturnType { get; }

        /// <summary>
        /// 方法类型
        /// </summary>
        public FastActionType ActionType { get; }

        /// <summary>
        /// 方法返回异步类型判断
        /// </summary>
        public FastActionTypeTask ActionTypeTask { get; }

        /// <summary>
        /// 特性列表
        /// </summary>
        public List<object> AttributeList { get; } = [];

        /// <summary>
        /// 是否必须释放
        /// </summary>
        internal bool NeedDispose { get; set; }

        /// <summary>
        /// 是否是事务
        /// </summary>
        internal bool IsTran { get; set; }

        /// <summary>
        /// 是否允许重复读取body
        /// </summary>
        internal bool EnableBuffering { get; }

        /// <summary>
        /// 限流个数
        /// </summary>
        public int RateLimitCount { get; internal set; }

        /// <summary>
        /// 限流key
        /// </summary>
        public string RateLimitKey { get; internal set; }

        /// <summary>
        /// 限流错误信息
        /// </summary>
        public string RateLimitMsg { get; internal set; }

        /// <summary>
        /// 限流错误码
        /// </summary>
        public int RateLimitCode { get; internal set; }

        /// <summary>
        /// 是否是Json异步流
        /// </summary>
        public bool IsJsonStream { get; internal set; }

        /// <summary>
        /// 是否传入流内容
        /// </summary>
        public bool IsPostStream { get; internal set; }

        /// <summary>
        /// 是否是表单
        /// </summary>
        public bool IsForm { get; internal set; }

        /// <summary>
        /// 是否上传文件
        /// </summary>
        public bool IsUpload { get; internal set; }

        /// <summary>
        /// 是都下载
        /// </summary>
        public bool IsDownload { get; internal set; }

        /// <summary>
        /// 路径名称(RouteData的key)
        /// </summary>
        public string PathName { get; internal set; }

    }
}
